package com.yserp.car.service.impl;
import com.yserp.car.service.TCarInfoServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import com.yserp.car.entity.TCarInfoEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.io.Serializable;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.MyClassLoader;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.cgform.enhance.CgformEnhanceJavaInter;

@Service("tCarInfoService")
@Transactional
public class TCarInfoServiceImpl extends CommonServiceImpl implements TCarInfoServiceI {

	
 	public void delete(TCarInfoEntity entity) throws Exception{
 		super.delete(entity);
 		//执行删除操作增强业务
		this.doDelBus(entity);
 	}
 	
 	public Serializable save(TCarInfoEntity entity) throws Exception{
 		Serializable t = super.save(entity);
 		//执行新增操作增强业务
 		this.doAddBus(entity);
 		return t;
 	}
 	
 	public void saveOrUpdate(TCarInfoEntity entity) throws Exception{
 		super.saveOrUpdate(entity);
 		//执行更新操作增强业务
 		this.doUpdateBus(entity);
 	}
 	
 	/**
	 * 新增操作增强业务
	 * @param t
	 * @return
	 */
	private void doAddBus(TCarInfoEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 更新操作增强业务
	 * @param t
	 * @return
	 */
	private void doUpdateBus(TCarInfoEntity t) throws Exception{
		//-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	/**
	 * 删除操作增强业务
	 * @param id
	 * @return
	 */
	private void doDelBus(TCarInfoEntity t) throws Exception{
	    //-----------------sql增强 start----------------------------
	 	//-----------------sql增强 end------------------------------
	 	
	 	//-----------------java增强 start---------------------------
	 	//-----------------java增强 end-----------------------------
 	}
 	
 	private Map<String,Object> populationMap(TCarInfoEntity t){
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("id", t.getId());
		map.put("create_name", t.getCreateName());
		map.put("create_by", t.getCreateBy());
		map.put("create_date", t.getCreateDate());
		map.put("update_name", t.getUpdateName());
		map.put("update_by", t.getUpdateBy());
		map.put("update_date", t.getUpdateDate());
		map.put("sys_org_code", t.getSysOrgCode());
		map.put("sys_company_code", t.getSysCompanyCode());
		map.put("bpm_status", t.getBpmStatus());
		map.put("car_num", t.getCarNum());
		map.put("car_type", t.getCarType());
		map.put("car_hzrs", t.getCarHzrs());
		map.put("car_jiashizheng", t.getCarJiashizheng());
		map.put("car_buy_money", t.getCarBuyMoney());
		map.put("car_buy_date", t.getCarBuyDate());
		map.put("car_vmi", t.getCarVmi());
		map.put("car_engineno", t.getCarEngineno());
		map.put("car_paiqiliang", t.getCarPaiqiliang());
		map.put("car_zaizhong", t.getCarZaizhong());
		map.put("car_fuel", t.getCarFuel());
		map.put("car_driver", t.getCarDriver());
		map.put("nj_riqi1", t.getNjRiqi1());
		map.put("nj_riqi2", t.getNjRiqi2());
		map.put("car_status", t.getCarStatus());
		map.put("by1", t.getBy1());
		map.put("by2", t.getBy2());
		map.put("by3", t.getBy3());
		map.put("by4", t.getBy4());
		map.put("by5", t.getBy5());
		map.put("car_chpxh", t.getCarChpxh());
		map.put("car_clwgchc", t.getCarClwgchc());
		map.put("car_bzsj", t.getCarBzsj());
		map.put("car_fdjgl", t.getCarFdjgl());
		map.put("car_hdrsh", t.getCarHdrsh());
		map.put("car_qdxsh", t.getCarQdxsh());
		map.put("car_bsqxsh", t.getCarBsqxsh());
		map.put("car_csys", t.getCarCsys());
		map.put("car_chbgs", t.getCarChbgs());
		map.put("car_zhil", t.getCarZhil());
		map.put("car_pic", t.getCarPic());
		return map;
	}
 	
 	/**
	 * 替换sql中的变量
	 * @param sql
	 * @param t
	 * @return
	 */
 	public String replaceVal(String sql,TCarInfoEntity t){
 		sql  = sql.replace("#{id}",String.valueOf(t.getId()));
 		sql  = sql.replace("#{create_name}",String.valueOf(t.getCreateName()));
 		sql  = sql.replace("#{create_by}",String.valueOf(t.getCreateBy()));
 		sql  = sql.replace("#{create_date}",String.valueOf(t.getCreateDate()));
 		sql  = sql.replace("#{update_name}",String.valueOf(t.getUpdateName()));
 		sql  = sql.replace("#{update_by}",String.valueOf(t.getUpdateBy()));
 		sql  = sql.replace("#{update_date}",String.valueOf(t.getUpdateDate()));
 		sql  = sql.replace("#{sys_org_code}",String.valueOf(t.getSysOrgCode()));
 		sql  = sql.replace("#{sys_company_code}",String.valueOf(t.getSysCompanyCode()));
 		sql  = sql.replace("#{bpm_status}",String.valueOf(t.getBpmStatus()));
 		sql  = sql.replace("#{car_num}",String.valueOf(t.getCarNum()));
 		sql  = sql.replace("#{car_type}",String.valueOf(t.getCarType()));
 		sql  = sql.replace("#{car_hzrs}",String.valueOf(t.getCarHzrs()));
 		sql  = sql.replace("#{car_jiashizheng}",String.valueOf(t.getCarJiashizheng()));
 		sql  = sql.replace("#{car_buy_money}",String.valueOf(t.getCarBuyMoney()));
 		sql  = sql.replace("#{car_buy_date}",String.valueOf(t.getCarBuyDate()));
 		sql  = sql.replace("#{car_vmi}",String.valueOf(t.getCarVmi()));
 		sql  = sql.replace("#{car_engineno}",String.valueOf(t.getCarEngineno()));
 		sql  = sql.replace("#{car_paiqiliang}",String.valueOf(t.getCarPaiqiliang()));
 		sql  = sql.replace("#{car_zaizhong}",String.valueOf(t.getCarZaizhong()));
 		sql  = sql.replace("#{car_fuel}",String.valueOf(t.getCarFuel()));
 		sql  = sql.replace("#{car_driver}",String.valueOf(t.getCarDriver()));
 		sql  = sql.replace("#{nj_riqi1}",String.valueOf(t.getNjRiqi1()));
 		sql  = sql.replace("#{nj_riqi2}",String.valueOf(t.getNjRiqi2()));
 		sql  = sql.replace("#{car_status}",String.valueOf(t.getCarStatus()));
 		sql  = sql.replace("#{by1}",String.valueOf(t.getBy1()));
 		sql  = sql.replace("#{by2}",String.valueOf(t.getBy2()));
 		sql  = sql.replace("#{by3}",String.valueOf(t.getBy3()));
 		sql  = sql.replace("#{by4}",String.valueOf(t.getBy4()));
 		sql  = sql.replace("#{by5}",String.valueOf(t.getBy5()));
 		sql  = sql.replace("#{car_chpxh}",String.valueOf(t.getCarChpxh()));
 		sql  = sql.replace("#{car_clwgchc}",String.valueOf(t.getCarClwgchc()));
 		sql  = sql.replace("#{car_bzsj}",String.valueOf(t.getCarBzsj()));
 		sql  = sql.replace("#{car_fdjgl}",String.valueOf(t.getCarFdjgl()));
 		sql  = sql.replace("#{car_hdrsh}",String.valueOf(t.getCarHdrsh()));
 		sql  = sql.replace("#{car_qdxsh}",String.valueOf(t.getCarQdxsh()));
 		sql  = sql.replace("#{car_bsqxsh}",String.valueOf(t.getCarBsqxsh()));
 		sql  = sql.replace("#{car_csys}",String.valueOf(t.getCarCsys()));
 		sql  = sql.replace("#{car_chbgs}",String.valueOf(t.getCarChbgs()));
 		sql  = sql.replace("#{car_zhil}",String.valueOf(t.getCarZhil()));
 		sql  = sql.replace("#{car_pic}",String.valueOf(t.getCarPic()));
 		sql  = sql.replace("#{UUID}",UUID.randomUUID().toString());
 		return sql;
 	}
 	
 	/**
	 * 执行JAVA增强
	 */
 	private void executeJavaExtend(String cgJavaType,String cgJavaValue,Map<String,Object> data) throws Exception {
 		if(StringUtil.isNotEmpty(cgJavaValue)){
			Object obj = null;
			try {
				if("class".equals(cgJavaType)){
					//因新增时已经校验了实例化是否可以成功，所以这块就不需要再做一次判断
					obj = MyClassLoader.getClassByScn(cgJavaValue).newInstance();
				}else if("spring".equals(cgJavaType)){
					obj = ApplicationContextUtil.getContext().getBean(cgJavaValue);
				}
				if(obj instanceof CgformEnhanceJavaInter){
					CgformEnhanceJavaInter javaInter = (CgformEnhanceJavaInter) obj;
					javaInter.execute("t_car_info",data);
				}
			} catch (Exception e) {
				e.printStackTrace();
				throw new Exception("执行JAVA增强出现异常！");
			} 
		}
 	}
}